#include<student_info_management.h>
#include<log.h>
#include<iostream>
#include<string>
#include<map>

extern std::map<std::string,int> score;

Student read_student(int flag)
{
	if(flag)
		printf("input num name courses_number courses_nums score_sum of the student\n");

	std::string num,name;
	std::cin>>num>>name;
	Student res(num,name);
	int n;
	std::cin>>n;
	std::string temp;
	for(int i=0;i<n;++i)
		std::cin>>temp,res.courses.push_back(temp),res.score_sum+=score[temp];
	
	return res;
}

void Student_management::add_info(Student new_stu)
{
	this->students.push_back(new_stu);
}

void Student_management::del_info(const std::string &stu_num)
{
	for(int i=0;i<this->students.size();++i)
		if(this->students[i].num==stu_num)
		{
			std::swap(this->students[i],this->students[this->students.size()-1]);
			Log("delete student num:%s\n",this->students[i].num.c_str());
			this->students.pop_back();
		}
}

void Student_management::mod_info(const std::string &stu_num)
{
	for(int i=0;i<this->students.size();++i)
		if(this->students[i].num==stu_num)
		{
			std::swap(this->students[i],this->students[this->students.size()-1]);
			Log("modify student num:%s\n",this->students[i].num.c_str());
			this->students.pop_back();
		}

	this->add_info(read_student(1));
}

void Student_management::check_info(const std::string &stu_num)
{
	for(int i=0;i<this->students.size();++i)
		if(this->students[i].num==stu_num)
		{
			printf("num:%s\nname:%s\nscore_sum:%d\n",this->students[i].num.c_str(),this->students[i].name.c_str(),this->students[i].score_sum);
			for(int j=0;j<this->students[i].courses.size();++j)
				printf("%s\n",this->students[i].courses[j].c_str());
		}
}
